#ifndef _APPVIEWIMPL_H_
#define _APPVIEWIMPL_H_

#include <dlcom/cominc.h>

#include <io/iframe.h>
#include <io/iiodevice.h>
#include <io/isocket.h>
#include <io/ioperation.h>
#include <io/itimer.h>

#include <net/inet.h>
#include <net/idns.h>
#include <net/ihttp.h>

#include <msgbus/imsgbus.h>

//{a7957a54-37cb-42a4-9ee8-599168c2a3d1}
_DEF_CLSID(CLSID_AppView, 0xA7957A54, 0x37CB, 0x42A4, 0x9E, 0xE8, 0x59, 0x91, 0x68, 0xC2, 0xA3, 0xD1);

class CAppViewImpl : public IPlugin, public IPluginRun, public ISockProc, public CUnknownImp
{
public:
    CAppViewImpl(void);
    virtual ~CAppViewImpl(void);

public:
    BEGIN_STDCOM_MAP
    STDCOM_INTERFACE_ENTRY_UNKNOWN_(IPlugin)
    STDCOM_INTERFACE_ENTRY(IPlugin)
    STDCOM_INTERFACE_ENTRY(IPluginRun)
    STDCOM_INTERFACE_ENTRY(ISockProc)
    END_STDCOM_MAP

    // IPlugin
    std_method(Init)(IBase* pRot, IBase* pBase);
    std_method(Uninit)();

    // IPluginRun
    std_method(Start)(_pid_t pid, unsigned int type);
    std_method(Stop)(unsigned int exit);

    // ISockProc
    std_method(OnSockSend)(crtid id, crterr error_code, buf_ptr buf, buf_len size);
    std_method(OnSockRecv)(crtid id, crterr error_code, buf_ptr buf, buf_len size);
    std_method(OnSockConnect)(crtid id, crterr error_code, _sock_t fd);
    std_method(OnSockEvent)(crtid id, crtid event, crterr error_code, _sock_t fd);

    HRESULT InitBus();
    HRESULT UnInitBus();

private:
    _lComPtr<IRot> m_pRot;
    _lComPtr<IAsynFrame> m_pIAsynFrame;
    _lComPtr<IHttp> m_pIHttp;
    _lComPtr<IMsgBus> m_pIMsgBus;
    _lComPtr<IBroker> m_pIBroker;
    _lComPtr<IConsumer> m_pIConsumer;
    _lComPtr<IProducer> m_pIProducer;
    _lComPtr<IAgent> m_pIAgent;
};
#endif
